﻿using System;
using System.Linq;
using Orange.Logistics.Models;
using Orange.Logistics.Infrastructure;
using Orange.Logistics.Services;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Orange.Logistics.Controllers {
    public class VenueStaffController : BaseController<VenueStaff> {
        private readonly IVenueService service;

        public VenueStaffController(IVenueService service)
            : base(service) {
            this.service = service;
        }

        public override JsonResult GetGrid() {
            InitPager();
            var list = service.GetGrid();
            int total = list.Count();
            IEnumerable<dynamic> source = null;
            if (PG.asc) {
                source = list.OrderBy(GetOrderBy2(PG.sort));
            } else {
                source = list.OrderByDescending(GetOrderBy2(PG.sort));
            }
            return Json(new { Rows = PagedList<dynamic>(source), Total = total });
        }
       

        protected override Func<VenueStaff, object> GetOrderBy(string sort) {
            return c => {
                switch (sort) {
                    case "Contactor":
                        return c.Contactor;
                    case "Birthdate":
                        return c.Birthdate;
                    case "Jobsid":
                        return c.Jobsid;
                    case "Idcard":
                        return c.Idcard;
                    case "Storeid":
                        return c.Storeid;
                    default:
                        return c.Id;
                }
            };

        }

        protected Func<dynamic, object> GetOrderBy2(string sort) {
            return c => {
                switch (sort) {
                    case "Contactor":
                        return c.Contactor;
                    case "Birthdate":
                        return c.Birthdate;
                    case "Jobsid":
                        return c.Jobsid;
                    case "Idcard":
                        return c.Idcard;
                    case "Storeid":
                        return c.Storeid;
                    default:
                        return c.Id;
                }
            };
        }
    }
}
